package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.QueryGroupDTO;
import top.hcode.hoj.pojo.entity.group.Group;
import top.hcode.hoj.pojo.vo.GroupVO;
import top.hcode.hoj.service.admin.AdminGroupService;

@RestController
@RequestMapping("/api/admin")
@RequiredArgsConstructor
@Slf4j
public class AdminGroupController {

    private final AdminGroupService groupService;

    @GetMapping("/group/list")
    @ApiOperation(value = "获取团队列表", notes = "获取团队列表")
    public CommonResult<IPage<GroupVO>> getGroupList(QueryGroupDTO queryGroupDto) {
        return CommonResult.successResponse(groupService.getGroupList(queryGroupDto));
    }

    @PostMapping("/group/save")
    @ApiOperation(value = "保存团队，支持新建和更新")
    public CommonResult<Group> saveGroup(@Validated @RequestBody Group group) {
        return CommonResult.successResponse(groupService.saveGroup(group));
    }

    @PostMapping("/group/delete")
    @ApiOperation(value = "删除团队")
    public CommonResult<Void> deleteGroup(@Validated @RequestBody BaseIdDTO idDTO) {
        groupService.deleteGroup(idDTO.getId());
        return CommonResult.successResponse();
    }

    @GetMapping("/group/detail")
    @ApiOperation(value = "获取团队详情")
    public CommonResult<Group> getGroup(@RequestParam("id") Long id) {
        return CommonResult.successResponse(groupService.getGroupDetail(id));
    }

    // 可以根据需要继续添加更多的方法
}